package com.promfy.bughunter.domain;

import com.promfy.bughunter.R;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.format.DateFormat;

public class Leaves {
	private Canvas canvas;
	private Context context;
	private int screenW;
	private int screenH;
	private Paint paint;
	private int index=100;
	private static Bitmap[] leaves = new Bitmap[2];	public Leaves(Canvas canvas, Context context, int screenW, int screenH) {
		super();
		this.canvas = canvas;
		this.context = context;
		this.screenW = screenW;
		this.screenH = screenH;
		paint = new Paint();
		paint.setTextSize(30);
		paint.setAntiAlias(true);
		paint.setColor(Color.WHITE);
		
		if (leaves[0] == null)
			leaves[0] = BitmapFactory.decodeResource(context.getResources(),
					R.drawable.leaf_1);
		if (leaves[1] == null)
			leaves[1] = BitmapFactory.decodeResource(context.getResources(),
					R.drawable.leaf_2);

	}


	public int getIndex() {
		if (index > 1000) index = 100;
		return index++;
	}

	

	/**
	 * flush score board in time;
	 * if timeout, return false;
	 */
	public boolean runLeaves(){
		canvas.drawBitmap(leaves[getLeafAnimIndex()], screenW - leaves[getLeafAnimIndex()].getWidth(), 0, paint);
		return true;
	}

	/**
	 * return index to show anima of leaves.
	 */
	private int getLeafAnimIndex(){
		if(getIndex()%10<=5){
			return 0;
		}else{
			return 1;
		}
		
	}
}
